package com.woniuxy.micromedicalserver.hospitalmanage.controller;



import com.woniuxy.micromedicalserver.bean.HospitalBean;
import com.woniuxy.micromedicalserver.bean.ResultMsg;
import com.woniuxy.micromedicalserver.hospitalmanage.service.IHospitalService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/hospital")
@RestController
public class HospitalController {

    @Resource
    private IHospitalService hospitalServiceImpl;


    @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg getHospitalByID(@PathVariable("id") Integer ID){
        HospitalBean hospitalBean = hospitalServiceImpl.selectByID(ID);
        return new ResultMsg(true,hospitalBean);
    }

    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg getAllHospital(HospitalBean hospitalBean){
        List<HospitalBean> list = hospitalServiceImpl.selectAllHospital(hospitalBean);
        return new ResultMsg(true,list);
    }


    @PostMapping(value = "/insert", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg insert(HospitalBean hospitalBean){
        hospitalServiceImpl.insertHospital(hospitalBean);
        return new ResultMsg(true);
    }


    @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg show(@PathVariable("id") Integer ID,  HospitalBean hospitalBean){
        hospitalBean.setId(ID);
        hospitalServiceImpl.updateHospital(hospitalBean);
        return new ResultMsg(true);
    }

    @DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg delete(@PathVariable("id") Integer ID, HospitalBean hospitalBean){
        hospitalBean.setId(ID);
        hospitalServiceImpl.updateHospital(hospitalBean);
        return new ResultMsg(true);
    }

















}
